2  Introduction to R

2.1 Learning Outcomes

By the end of this section you should:

  • have an up-to-date version of R installed on your computer

  • have an up-to-date version of RStudio installed on your computer

2.2 Introduction

Throughout the MSc programme, we’ll use R as our ‘standard’ environment for analysis. R has a number of advantages, not least that it is free! It’s also highly flexible and there are often many different ways to carry out the same tasks (this is also one of it’s potential drawbacks!)

It’s also very widely used in data analytics and there are many libraries, books and tutorials that can help you to learn and develop with R.

It’s important to note that R is not the only environment used for data analytics. For example, Python is also popular, especially for machine learning. 1

We’ve decided to concentrate on R for this MSc because it’s the environment with which we’re most familiar. Also, many of the concepts and processes are easily transferred into other environments.

Note

If you’re keen to develop your skills further, you may wish to replicate the various exercises and activities in this module in Python!

Caveat

This introduction really just scratches the surface of R. It’s intended to help you achieve basic competence in R and some familiarity with how R (and RStudio) work. It certainly doesn’t cover everything!

Also, you may already be familiar with some (or all) of the concepts introduced. Please remember that this introduction is intended to ensure that everyone in the group has basic competence in R, and a little revision won’t do any harm.

Finally, you should note that there are often many ways to do the same thing in R. You might encounter this throughout your MSc. Remember that there is no ‘right’ or ‘wrong’ way to do things, and much of it is down to personal preference.

2.3 Installing R

You’re going to install two different pieces of software.

The first is R. This is the base package and is capable of running R code by itself. It has a very minimal interface and isn’t the most user-friendly!

Therefore, after we’ve installed R, we’re going to install another piece of software, RStudio, which provides a more user-friendly interface. RStudio basically allows you to run R with a better front-end.

Important

You need to have R already installed on your computer in order to use RStudio.

Downloading R

  • Visit the Comprehensive R Archive Network (CRAN) website

  • Select appropriate version for your operating system (Windows, macOS)

  • Windows: Click on “Download R for Windows” -> “base” -> “Download R x.x.x for Windows” (where x.x.x is the latest version)

  • macOS: Click on “Download R for (Mac) OS X” -> “R-x.x.x.pkg” (where x.x.x is the latest version)

Installing R

  • Windows: Locate the downloaded R installer file (.exe) and double-click to launch installation. Follow the prompts and accept default settings during installation process. Wait for installation to complete and close installer.
  • macOS: Locate the downloaded R installer file (.pkg) and double-click to launch installation. Follow the prompts and accept default settings during installation process. Wait for installation to complete and close installer.

2.4 Verifying the R Installation

  • Launch R from your applications menu or by searching for “R” on your computer.

  • A new window called the R console should open, displaying the R version number and a “>” prompt.

  • Type version in the R console and press Enter to verify that R is installed correctly.

    Note

    In these tutorials, any text you see in blue represents a command I have entered directly into the console.

2.5 Installing RStudio

Introduction

RStudio is an integrated development environment (IDE) for R, a powerful statistical programming language. This guide will walk you through the process of installing RStudio on your computer.

Download RStudio

  • Visit the official RStudio website

  • Click on the “Products” link on the top menu.

  • Under “RStudio Desktop,” click on the “Download” button.

  • On the RStudio Desktop download page, you’ll see different versions available for Windows, macOS, and Linux. Choose the version that matches your operating system and click on the associated download link.

  • Once the download is complete, run the installer and follow the instructions provided.

Launch RStudio

After the installation is complete, you can launch RStudio.

  • Locate the RStudio icon on your desktop or in your applications folder.

  • Double-click on the RStudio icon to launch the application.

2.6 Useful Resources

Installing R

Installing RStudio

General Resources


  1. There’s a useful summary of some of the key differences between the two platforms here.↩︎